//
// Created by Administrator on 2021/11/11.
// May Saint Diana bless you!
//
#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    vector<int> findDuplicates(vector<int> &nums) {
        vector<int> ans;
        for (int i = 0; i < nums.size(); ++i) {
            int num = abs(nums[i]);
            if (nums[num - 1] > 0)
                nums[num - 1] *= -1;
            else
                ans.push_back(abs(num));
        }
        return ans;
    }
};

int main() {
    vector<int> nums{4, 3, 2, 7, 8, 2, 3, 1};
    Solution solution;
    auto ans = solution.findDuplicates(nums);
    for (const auto &x: ans) cout << x << endl;
    return 0;
}


